package com.xr.framework.security.interceptor;

import com.xr.common.utils.ServletUtils;
import com.xr.common.utils.StringUtils;
import com.xr.common.utils.ip.AddressUtils;
import com.xr.common.utils.ip.IpUtils;
import com.xr.framework.miniprogram.service.UserTokenService;
import com.xr.miniprogram.domain.vo.MiniProgramUserVO;
import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

public class MyInterceptor implements HandlerInterceptor {

    @Resource
    private UserTokenService userTokenService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse
    response, Object handler) throws Exception {

        MiniProgramUserVO miniProgramUserVO = userTokenService.getLoginUser(request);
        if (StringUtils.isNotNull(miniProgramUserVO))
        {
            userTokenService.verifyToken(miniProgramUserVO);
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse
    response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse
    response, Object handler, Exception ex) throws Exception {

    }
}